﻿using crip.Database;
using crip.Services.IRepositorys;

namespace crip.Services.Repositorys
{
    public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity : class, new ()
    {
        private CripDbContext _cripDbContext;
        public BaseRepository(CripDbContext cripDbContext)
        {
            _cripDbContext = cripDbContext;
        }
        public void Delete (TEntity entity)
        {
            _cripDbContext.Remove(entity);
        }

        public async Task<TEntity> GetByIdAsync(Guid? id)
        {
         return  await _cripDbContext.FindAsync<TEntity>(id);
        }
        #region 批量删除实体
        public void DeleteEntitys(List<TEntity> entity)
        {
            _cripDbContext.RemoveRange(entity);
        }
        #endregion
        public async Task SaveAsync()
        {
            await _cripDbContext.SaveChangesAsync();
        }
    }

}
